const express = require('express');
const router = express.Router();

const DBHelper = require('../utils/DBHelper');
const sql = require('../sqlMap');

// 查询

router.post('/selectMovieinfo', (req,res) => {
    let sqlStr = sql.movie.selectall;
    let conn = new DBHelper().getConn();
    conn.query(sqlStr, (err, result) => {
        if (err) {
            console.log(err);
            res.json(err);
        } else {
            res.json(result);
        }
    });
    conn.end();
});

router.post('/selectMovieid', (req,res) => {
    let params = req.body;
    let sqlStr = sql.movie.selectid;
    let conn = new DBHelper().getConn();
    conn.query(sqlStr, [params.id],(err, result) => {
        if (err) {
            console.log(err);
            res.json(err);
        } else {
            console.log(result);
            res.json(result);
        }
    });
    conn.end();
});

router.post('/selectcinema', (req,res) => {
    let sqlStr = sql.cinema.selectall;
    let conn = new DBHelper().getConn();
    conn.query(sqlStr,(err, result) => {
        if (err) {
            console.log(err);
            res.json(err);
        } else {
            console.log(result);
            res.json(result);
        }
    });
    conn.end();
});

module.exports = router;
